<template>
  <div class="login-page">
    <!-- 顶部导航 -->
    <div class="login-header">
      <div class="header-container">
        <router-link to="/" class="logo">
          <img src="../assets/logo.png" alt="小米账号" />
          <span>小米账号</span>
        </router-link>
        <div class="header-right">
          <a href="#">用户协议</a>
          <a href="#">隐私政策</a>
          <a href="#">帮助中心</a>
          <a href="#">中文(简体)</a>
        </div>
      </div>
    </div>

    <!-- 主要内容区 -->
    <div class="login-container">
      <div class="login-box">
        <div class="login-tabs">
          <router-link to="/login" class="tab">登录</router-link>
          <span class="active">注册</span>
        </div>
        
        <el-form :model="registerForm" class="login-form">
          <el-form-item>
            <el-input 
              v-model="registerForm.username" 
              placeholder="用户名"
              size="large"
            >
            </el-input>
          </el-form-item>
          
          <el-form-item>
            <el-input 
              v-model="registerForm.phone" 
              placeholder="手机号码"
              size="large"
            >
            </el-input>
          </el-form-item>
          
          <el-form-item>
            <el-input 
              v-model="registerForm.password" 
              type="password" 
              placeholder="密码"
              size="large"
              :suffix-icon="showPassword ? 'View' : 'Hide'"
              @click-suffix="togglePasswordVisibility"
            >
            </el-input>
          </el-form-item>

          <el-form-item>
            <el-input 
              v-model="registerForm.confirmPassword" 
              type="password" 
              placeholder="确认密码"
              size="large"
              :suffix-icon="showConfirmPassword ? 'View' : 'Hide'"
              @click-suffix="toggleConfirmPasswordVisibility"
            >
            </el-input>
          </el-form-item>

          <div class="agreement-row">
            <el-checkbox v-model="registerForm.agreement">
              已阅读并同意小米账号<a href="#">用户协议</a>和<a href="#">隐私政策</a>
            </el-checkbox>
          </div>

          <el-button 
            type="primary" 
            class="login-btn" 
            size="large"
            :disabled="!registerForm.agreement"
            @click="handleRegister"
          >
            立即注册
          </el-button>

          <div class="other-login">
            <div class="divider">
              <span>其他方式注册</span>
            </div>
            <div class="social-login">
              <a href="#" class="social-icon alipay"></a>
              <a href="#" class="social-icon wechat"></a>
              <a href="#" class="social-icon qq"></a>
              <a href="#" class="social-icon weibo"></a>
            </div>
          </div>
        </el-form>
      </div>
    </div>

    <!-- 底部版权信息 -->
    <div class="login-footer">
      <p>小米公司版权所有-京ICP备10046444-京公网安备11010802020134号-京ICP证110507号</p>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();
const showPassword = ref(false);
const showConfirmPassword = ref(false);
const registerForm = ref({
  username: '',
  phone: '',
  password: '',
  confirmPassword: '',
  agreement: false
});

const handleRegister = () => {
  if (!registerForm.value.agreement) {
    ElMessage.warning('请先同意用户协议和隐私政策');
    return;
  }
  
  if (registerForm.value.password !== registerForm.value.confirmPassword) {
    ElMessage.error('两次输入的密码不一致');
    return;
  }
  
  console.log('注册信息：', registerForm.value);
  router.push('/login');
};

const togglePasswordVisibility = () => {
  showPassword.value = !showPassword.value;
};

const toggleConfirmPasswordVisibility = () => {
  showConfirmPassword.value = !showConfirmPassword.value;
};
</script>

<style lang="scss" scoped>
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #8b75ff 0%, #6f47ff 100%);
  position: relative;
  display: flex;
  flex-direction: column;
}

.login-header {
  background: transparent;
  padding: 20px 0;
  
  .header-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
  }

  .logo {
    display: flex;
    align-items: center;
    text-decoration: none;
    
    img {
      height: 40px;
      margin-right: 10px;
    }
    
    span {
      color: #fff;
      font-size: 20px;
    }
  }

  .header-right {
    a {
      color: #fff;
      text-decoration: none;
      margin-left: 20px;
      font-size: 14px;
      
      &:hover {
        opacity: 0.8;
      }
    }
  }
}

.login-container {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 40px;
}

.login-box {
  width: 400px;
  background: #fff;
  border-radius: 8px;
  padding: 30px;
  margin-right: 10%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.login-tabs {
  display: flex;
  margin-bottom: 30px;
  border-bottom: 1px solid #e0e0e0;
  padding-bottom: 15px;
  
  span, .tab {
    font-size: 24px;
    margin-right: 20px;
    color: #757575;
    text-decoration: none;
    cursor: pointer;
    
    &.active {
      color: #ff6700;
      position: relative;
      
      &:after {
        content: '';
        position: absolute;
        bottom: -16px;
        left: 0;
        width: 100%;
        height: 2px;
        background: #ff6700;
      }
    }
  }
}

.login-form {
  .el-input {
    --el-input-height: 50px;
    margin-bottom: 20px;
  }
}

.agreement-row {
  margin: 20px 0;
  
  a {
    color: #ff6700;
    text-decoration: none;
    
    &:hover {
      text-decoration: underline;
    }
  }
}

.login-btn {
  width: 100%;
  height: 50px;
  background: #ff6700;
  border: none;
  font-size: 16px;
  
  &:hover {
    background: #f25807;
  }
  
  &:disabled {
    background: #ffdfd3;
  }
}

.other-login {
  margin-top: 30px;
  
  .divider {
    display: flex;
    align-items: center;
    color: #999;
    font-size: 14px;
    margin-bottom: 20px;
    
    &:before,
    &:after {
      content: '';
      flex: 1;
      height: 1px;
      background: #e0e0e0;
    }
    
    span {
      padding: 0 15px;
    }
  }
  
  .social-login {
    display: flex;
    justify-content: center;
    gap: 20px;
    
    .social-icon {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      background: #f5f5f5;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.3s;
      
      &:hover {
        background: #e0e0e0;
      }
      
      &.alipay { background-image: url(支付宝图标URL); }
      &.wechat { background-image: url(微信图标URL); }
      &.qq { background-image: url(QQ图标URL); }
      &.weibo { background-image: url(微博图标URL); }
    }
  }
}

.login-footer {
  text-align: center;
  padding: 20px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
}
</style> 